package com.health.web.controller.teahouse;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.teahouse.domain.Recipes;
import com.health.teahouse.service.IRecipesService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;

/**
 * 菜谱管理Controller
 * 
 * @author yang
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/teahouse/recipes")
public class RecipesController extends BaseController
{
    @Autowired
    private IRecipesService recipesService;

    /**
     * 查询菜谱管理列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:recipes:list')")
    @GetMapping("/list")
    public TableDataInfo list(Recipes recipes)
    {
        startPage();
        List<Recipes> list = recipesService.selectRecipesList(recipes);
        return getDataTable(list);
    }

    /**
     * 导出菜谱管理列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:recipes:export')")
    @Log(title = "菜谱管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Recipes recipes)
    {
        List<Recipes> list = recipesService.selectRecipesList(recipes);
        ExcelUtil<Recipes> util = new ExcelUtil<Recipes>(Recipes.class);
        util.exportExcel(response, list, "菜谱管理数据");
    }

    /**
     * 获取菜谱管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:recipes:query')")
    @GetMapping(value = "/{recipeId}")
    public AjaxResult getInfo(@PathVariable("recipeId") Long recipeId)
    {
        return success(recipesService.selectRecipesByRecipeId(recipeId));
    }

    /**
     * 新增菜谱管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:recipes:add')")
    @Log(title = "菜谱管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Recipes recipes)
    {
        return toAjax(recipesService.insertRecipes(recipes));
    }

    /**
     * 修改菜谱管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:recipes:edit')")
    @Log(title = "菜谱管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Recipes recipes)
    {
        return toAjax(recipesService.updateRecipes(recipes));
    }

    /**
     * 删除菜谱管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:recipes:remove')")
    @Log(title = "菜谱管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recipeIds}")
    public AjaxResult remove(@PathVariable Long[] recipeIds)
    {
        return toAjax(recipesService.deleteRecipesByRecipeIds(recipeIds));
    }
}
